<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@page import="com.tjtt.tdm.base.StringUtil"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
	
	String itemname = request.getParameter("itemname");
	String danwei = request.getParameter("danwei");
	String leibie = request.getParameter("leibie");
	if(!StringUtil.isEmpty(itemname)){
	    itemname = StringUtil.encodingUrl(itemname);  
	}
	if(!StringUtil.isEmpty(leibie)){
	    leibie = StringUtil.encodingUrl(leibie);  
	}
	request.setAttribute("itemname", itemname);
	request.setAttribute("danwei", danwei);
	request.setAttribute("leibie", leibie);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"> 								
	<head> 	
	    <base target="_self"/>						
		<%@ include file="../jslib/jquerylib.jsp" %>
		<title>样品接收页面</title>
	    <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/lhgdialog/lhgcore.lhgdialog.min.js?skin=mac"></script>
        <link href="<%=request.getContextPath() %>/web/style/layout.css" type="text/css" rel="stylesheet"/>
        <link rel="stylesheet" href="<%=request.getContextPath() %>/jslib/ztree/css/zTreeStyle/zTreeStyle.css" type="text/css"/>
        <script type="text/javascript" src="<%=request.getContextPath() %>/jslib/ztree/jquery.ztree.core-3.4.js"></script>
        <script type='text/javascript' src="<%=request.getContextPath() %>/jslib/My97DatePicker/WdatePicker.js" defer="defer"></script>
	       <!-- 删除结果信息返回 -->
	    	<c:if test="${requestScope.message!=null}">
				<script type="text/javascript">
	  	 		     alert('<c:out value="${requestScope.message}"></c:out>');
	  	 		     window.close();
	  			</script>
	        </c:if>
	 
	<script type="text/javascript">
	$(document).ready(function(){
					$("#gridTable").jqGrid({
						url:'<%=request.getContextPath() %>/item!queryItemcanshuList.action?itemname='+encodeURIComponent(encodeURIComponent('${itemname}'))+'&danwei=${danwei}&leibie='+encodeURIComponent(encodeURIComponent('${leibie}')),
						datatype: "json",
						height: 350,
						width: 610, 
						autowidth: true, 
						colNames:['主键','检测项目','检测类别','检测参数'],
			            colModel:[
			              {name:'ROWNUM',index:'ROWNUM', width:70,key:true,hidden:true}, 
			              {name:'T_ITEMNAME',index:'T_ITEMNAME', width:200}, 
			              {name:'T_JIACELEIBIE',index:'T_JIACELEIBIE', width:180}, 
			              {name:'T_JIANCECANSHU',index:'T_JIANCECANSHU', width:150}
			            ],
						shrinkToFit:false,
						sortname:'T_JIANCECANSHU',
						sortorder:'asc',
						viewrecords:true,
						multiselect: true, // 是否显示复选框
						multiboxonly : true, 
						//gridview: true,  //提升速度
						rownumbers: true,//显示行号
						rownumWidth: 30, //行号的宽度
						rowNum:15,
						rowList:[15,20,50,200,500],
						toolbar: [false,"top"],
						jsonReader: {
							root:"rows",		// 数据行（默认为：rows）
							page: "page",  	// 当前页
							total: "total",  // 总页数
							records: "records",  // 总记录数
							repeatitems : false		// 设置成false，在后台设置值的时候，可以乱序。且并非每个值都得设
						},
						prmNames:{rows:"rows",page:"page",sort:"sidx",order:"sord",search:"search"},
						pager:"#gridPager",
						caption: "检测参数"
			});
			
			 //确定按钮
		     $("#entry").click(function(){
		         var ids = $("#gridTable").jqGrid("getGridParam", "selarrrow") + "";
		         if (!ids) {
		            alert("请先选择记录!");  
		            return false;  
		         } 
		         var params = {  
		             "ids": ids,
		             "flag":1
		          }; 
		         var actionUrl = "project/item!updateJiancecanshu.action";  
		             $.ajax({  
		                 url : actionUrl,  
		                 type : "post", 
		                 data : params,  
		                 dataType : "json",  
		                 cache : false,  
		             error : function(textStatus, errorThrown) {  
		                 alert("系统ajax交互错误: " + textStatus.value);  
		             },  
		             success : function(data, textStatus) {  
		                if(data.ajaxResult=='success'){
		                  alert("检测参数恢复成功!");
		                  window.close();
		                }
		                else{
		                  alert("检测参数恢复失败,请重试!");
		                  return false;
		                }   
		                 
		             }  
		         });
				
			});
				
		      /**
		     * 取消
		     */
		    $("#center").click(function(){
		        window.close();
		    });
	  });
	  //添加参数、修改参数
	  function addCanshu(flag){
	    var canshu = '';
	    if(flag==1){
	       var ids= $("#gridTable").jqGrid("getGridParam", "selarrrow") + "";
			if (!ids) {
			    alert("请先选择记录!");  
			    return false;  
			}
			if(ids.indexOf(",")!=-1){
				  alert("只能选择一条记录!");  
			      return false; 
			}
			var row = jQuery("#gridTable").jqGrid('getRowData',ids);//获取选中行.
			canshu = row.T_JIANCECANSHU;
			
	    }
	    var url = '<%=request.getContextPath()%>/view/gwm_item_canshuAdd.jsp?flag='+flag+'&itemname='+encodeURIComponent(encodeURIComponent('${itemname}'))+'&danwei=${danwei}&leibie='+encodeURIComponent(encodeURIComponent('${leibie}'))+'&canshu='+encodeURIComponent(encodeURIComponent(canshu));
	    var datas = window.showModalDialog(url,'',"dialogWidth=400px;dialogHeight=300px");
		gridSearchGrid();
	  } 
	  //删除参数
	  function deleteCanshu(){
	    var canshu = [];
	    var ids= $("#gridTable").jqGrid("getGridParam", "selarrrow") + "";
        if (!ids) {
		    alert("请先选择记录!");  
		    return false;  
		}
		var allIds = ids.split(",");
		for ( var i = 0; i < allIds.length; i++) {
			var id = allIds[i];
			var row = jQuery("#gridTable").jqGrid('getRowData',id);//获取选中行.
		    canshu.push(row.T_JIANCECANSHU);
		}
		var params = {  
			    "canshu":encodeURIComponent(canshu.join()),
		        "itemname":encodeURIComponent('${itemname}'),
		        "danwei":'${danwei}',
		        "leibie": encodeURIComponent('${leibie}')
		     };
			var actionUrl = "<%=request.getContextPath() %>/item!deleteGwmItemCanshu.action";  
			$.ajax({  
				  url : actionUrl,  
			      type : "post", 
			      data : params,  
			      dataType : "json",  
			      cache : false,  
			      async: false,//取消异步提交
			      error : function(textStatus, errorThrown) {  
			          alert("系统ajax交互错误: " + textStatus.value);  
			      },  
			      success : function(data, textStatus) {
			      	if(data.result=='success'){
			      		alert("删除成功！");       
			      		gridSearchGrid();  
			      	}else{
			      		alert("删除失败！");
			      	}
			    }  
			});	
	  }
	  //刷新列表
	  function gridSearchGrid(){
	        jQuery("#gridTable").jqGrid('setGridParam',
	              {
	                  url:'<%=request.getContextPath() %>/item!queryItemcanshuList.action?itemname='+encodeURIComponent(encodeURIComponent('${itemname}'))+'&danwei=${danwei}&leibie='+encodeURIComponent(encodeURIComponent('${leibie}'))
	              }).trigger("reloadGrid", [{page:1}]); 
	   }
	
	</script>
	</head>
	<body>
	<form action="" method="post" id="form1">
	      <table style="width: 100%;">
			   <tr style="align:left">
			   <td height="25" valign="top">
		         	<input id="add"    type='button' value='添 加' onclick="addCanshu(0)" class='button_b' />
					<input id="update" type='button' value='修 改' onclick='addCanshu(1)' class='button_b' />
					<input id="delete" type='button' value='删 除' onclick='deleteCanshu()' class='button_b' />
			   </td>
		      </tr>
		   </table>
	      <table style="width: 100%;" class="tableCont">
				<tr>
					<td>
						<table id="gridTable"></table>
						<div id="gridPager"></div>
					</td>
				</tr>
			</table>
	</form>
	</body>
</html>
